import { NAvatarGroup } from "naive-ui";
import type {
  AvatarGroupProps,
  AvatarGroupAvatarSlotProps,
  AvatarGroupRestSlotProps,
} from "naive-ui";
import { getSlotsDom } from "../utils";
import type { BaseComponentType } from "../types";
import type { HTMLAttributes } from "vue";
export type AvatarGroupFactoryConstructorType = {
  props?: AvatarGroupProps;
  defaultSlot?: BaseComponentType;
  attrs?: HTMLAttributes;
};
export class AvatarGroupFactory {
  private defaultSlot: BaseComponentType = null;
  private avatarSlot: (v?: AvatarGroupAvatarSlotProps) => BaseComponentType =
    () => null;
  private restSlot: (v?: AvatarGroupRestSlotProps) => BaseComponentType = () =>
    null;

  private props: AvatarGroupProps = {};
  private attrs: HTMLAttributes = {};

  constructor(param?: AvatarGroupFactoryConstructorType) {
    if (param?.props) this.setProps(param.props);
    if (param?.defaultSlot) this.setDefault(param.defaultSlot);
    if (param?.attrs) this.setAttrs(param.attrs);
  }
  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  setProps(props: AvatarGroupProps) {
    this.props = props;
    return this;
  }
  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this;
  }

  setAvatar(component: (v?: AvatarGroupAvatarSlotProps) => BaseComponentType) {
    this.avatarSlot = component;
    return this;
  }

  setRest(component: (v?: AvatarGroupRestSlotProps) => BaseComponentType) {
    this.restSlot = component;
    return this;
  }
  create() {
    return (
      <NAvatarGroup {...this.attrs} {...this.props}>
        {{
          default: () => getSlotsDom(this.defaultSlot),
          avatar: (info: AvatarGroupAvatarSlotProps) =>
            getSlotsDom(this.avatarSlot(info)),
          rest: (info: AvatarGroupRestSlotProps) =>
            getSlotsDom(this.restSlot(info)),
        }}
      </NAvatarGroup>
    );
  }
}
